home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / dec / qdss / qdtext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-26  |  7.4 KB  |  254 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26. #include "Xproto.h"
  27. #include "gcstruct.h"
  28. #include "windowstr.h"
  29. #include "qd.h"
  30. #include "qdgc.h"
  31. #ifndef X11R4
  32. #include "fontstr.h"
  33. #endif /* X11R4 */
  34. #include "servermd.h"
  35. #ifdef X11R4
  36. #include "fontstruct.h"
  37. #include "dixfontstr.h"
  38. #endif /* X11R4 */
  39.  
  40. void
  41. qdImageTextPix( pDraw, pGC, x0, y0, nChars, pStr)
  42.     DrawablePtr pDraw;
  43.     GCPtr    pGC;
  44.     int        x0, y0;
  45.     int        nChars;
  46.     char *    pStr;
  47. {
  48.     CHECK_MOVED(pGC, pDraw);
  49.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL) {
  50.     /* make dummy window and use that as the drawable */
  51.     SETUP_PIXMAP_AS_WINDOW(pDraw, pGC);
  52.     /*
  53.      * tlImageText is somewhat faster than qdImageTextKerned,
  54.      * but in the interest of simplicity, we just go for the more
  55.      * general case, without testing to see if that is needed.
  56.      */
  57.     qdImageTextKerned(pDraw, pGC, x0, y0, nChars, pStr);
  58.     CLEANUP_PIXMAP_AS_WINDOW(pGC);
  59.     }
  60.     else
  61.     miImageText8( pDraw, pGC, x0, y0, nChars, pStr);
  62. }
  63.  
  64. int
  65. qdPolyTextPix( pDraw, pGC, x0, y0, nChars, pStr)
  66.     DrawablePtr pDraw;
  67.     GCPtr    pGC;
  68.     int        x0, y0;
  69.     int     nChars;
  70.     char *    pStr;
  71. {
  72.     CHECK_MOVED(pGC, pDraw);
  73.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL) {
  74.     int width;
  75.     /* make dummy window and use that as the drawable */
  76.     SETUP_PIXMAP_AS_WINDOW(pDraw, pGC);
  77.     width = tlPolyText( pDraw, pGC, x0, y0, nChars, pStr);
  78.     CLEANUP_PIXMAP_AS_WINDOW(pGC);
  79.     return width;
  80.     }
  81.     else
  82.     return miPolyText8( pDraw, pGC, x0, y0, nChars, pStr);
  83. }
  84.  
  85. qdImageTextKerned( pDraw, pGC, x0, y0, nChars, pStr)
  86.     DrawablePtr pDraw;
  87.     GCPtr    pGC;
  88.     int        x0, y0;
  89.     int     nChars;
  90.     char *    pStr;
  91. {
  92.     xRectangle rect;
  93.     register unsigned char *p;
  94.     register int i, w;
  95. #ifndef X11R4
  96.     EncodedFontPtr pFont = pGC->font;
  97.     CharSetPtr pcs = pFont->pCS;
  98.     int chfirst = pFont->firstCol;
  99.     int chlast = pFont->lastCol;
  100.     register CharInfoPtr *ppCI = pFont->ppCI - chfirst;
  101. #else
  102.     FontPtr pFont = pGC->font;
  103.     FontInfoPtr pfi = pFont->pFI;
  104.     int chfirst = pFont->pFI->firstCol;
  105.     int chlast = pFont->pFI->lastCol;
  106.     register CharInfoPtr pCI;
  107. #endif /* X11R4 */
  108.     int saveAlu = pGC->alu;
  109.     int saveFillStyle = pGC->fillStyle;
  110.     int saveFgPixel = pGC->fgPixel;
  111.     pGC->fillStyle = FillSolid;
  112.  
  113. #ifdef X11R4
  114.     pCI = &pFont->pCI[-chfirst];
  115.  
  116. #endif /* X11R4 */
  117.     /* calculate width of string pStr */
  118.     for (w = 0, i = nChars, p = (unsigned char*)pStr; --i >= 0; ) {
  119.     register ch = *p++;
  120.     if (ch < chfirst || ch > chlast) {
  121. #ifndef X11R4
  122.         ch = pFont->defaultCh;
  123. #else
  124.         ch = pFont->pFI->chDefault;
  125. #endif /* X11R4 */
  126.         if (ch < chfirst || ch > chlast) continue;
  127.     }
  128. #ifndef X11R4
  129.     w += ppCI[ch]->metrics.characterWidth;
  130. #else
  131.     w += pCI[ch].metrics.characterWidth;
  132. #endif /* X11R4 */
  133.     }
  134.  
  135.     rect.x = x0;
  136. #ifndef X11R4
  137.     rect.y = y0 - pcs->fontAscent;
  138. #else
  139.     rect.y = y0 - pfi->fontAscent;
  140. #endif /* X11R4 */
  141.     rect.width = w;
  142. #ifndef X11R4
  143.     rect.height = pcs->fontAscent + pcs->fontDescent;
  144. #else
  145.     rect.height = pfi->fontAscent + pfi->fontDescent;
  146. #endif /* X11R4 */
  147.     if (saveFillStyle != FillSolid) InstalledGC = NULL;
  148.     pGC->alu = GXcopy;
  149.     pGC->fgPixel = pGC->bgPixel;
  150.     tlSolidRects(pDraw, pGC, 1, &rect);
  151.     pGC->fgPixel = saveFgPixel;
  152.     tlPolyText( pDraw, pGC, x0, y0, nChars, pStr);
  153.     if (saveFillStyle != FillSolid) InstalledGC = NULL;
  154.     pGC->alu = saveAlu;
  155.     pGC->fillStyle = saveFillStyle;
  156. }
  157.  
  158. void
  159. #ifndef X11R4
  160. qdPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci)
  161. #else
  162. qdPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  163. #endif /* X11R4 */
  164.     DrawablePtr pDrawable;
  165.     GC         *pGC;
  166.     int     x, y;
  167.     unsigned int nglyph;
  168.     CharInfoPtr *ppci;        /* array of character info */
  169. #ifdef X11R4
  170.     unsigned char *pglyphBase;  /* start of array of glyphs */
  171.  
  172. #endif /* X11R4 */
  173. {
  174.     int width, height;
  175.     int nbyLine;            /* bytes per line of padded pixmap */
  176. #ifndef X11R4
  177.     EncodedFontRec *pfont;
  178. #else
  179.     FontPtr pfont;
  180. #endif /* X11R4 */
  181.     register int i;
  182.     register int j;
  183.     unsigned char *pbits;        /* buffer for PutImage */
  184.     register unsigned char *pb;        /* temp pointer into buffer */
  185.     register CharInfoPtr pci;        /* currect char info */
  186.     register unsigned char *pglyph;    /* pointer bits in glyph */
  187.     int gWidth, gHeight;        /* width and height of glyph */
  188.     register int nbyGlyphWidth;        /* bytes per scanline of glyph */
  189.     int nbyPadGlyph;            /* server padded line of glyph */
  190.     QDPixRec dummyPixmap[1];
  191.  
  192.     if ((pDrawable->type == DRAWABLE_WINDOW) &&
  193.     (pGC->miTranslate))
  194.     {
  195.     x += pGC->lastWinOrg.x;
  196.     y += pGC->lastWinOrg.y;
  197.     }
  198.  
  199.     pfont = pGC->font;
  200. #ifndef X11R4
  201.     width = pfont->pCS->maxbounds.rightSideBearing - 
  202.     pfont->pCS->minbounds.leftSideBearing;
  203.     height = pfont->pCS->maxbounds.ascent + pfont->pCS->maxbounds.descent;
  204. #else
  205.     width = pfont->pFI->maxbounds.metrics.rightSideBearing - 
  206.     pfont->pFI->minbounds.metrics.leftSideBearing;
  207.     height = pfont->pFI->maxbounds.metrics.ascent +
  208.     pfont->pFI->maxbounds.metrics.descent;
  209. #endif /* X11R4 */
  210.  
  211.     nbyLine = PixmapBytePad(width, 1);
  212.     pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
  213.     if (!pbits)
  214.         return ;
  215.  
  216.     dummyPixmap->pixmap.drawable.type = DRAWABLE_PIXMAP;
  217.     dummyPixmap->pixmap.drawable.depth = 1;
  218.     dummyPixmap->pixmap.drawable.pScreen = pDrawable->pScreen;
  219.     QDPIX_X(dummyPixmap) = 0;
  220.     QDPIX_Y(dummyPixmap) = 0;
  221.     dummyPixmap->planes = 0;
  222.  
  223.     while(nglyph--) {
  224.     pci = *ppci++;
  225. #ifndef X11R4
  226.     pglyph = (unsigned char *)pci->pPriv;
  227. #else
  228.         pglyph = pglyphBase + pci->byteOffset;
  229. #endif /* X11R4 */
  230.     gWidth = GLYPHWIDTHPIXELS(pci);
  231.     gHeight = GLYPHHEIGHTPIXELS(pci);
  232.     nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
  233.     nbyPadGlyph = PixmapBytePad(gWidth, 1);
  234.  
  235.     for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
  236.         for (j = 0; j < nbyGlyphWidth; j++)
  237.         *pb++ = *pglyph++;
  238.  
  239.     QDPIX_WIDTH(&dummyPixmap->pixmap) = gWidth;
  240.     QDPIX_HEIGHT(&dummyPixmap->pixmap) = gHeight;
  241.     dummyPixmap->pixmap.devKind = PixmapBytePad(gWidth, 1);
  242.     QD_PIX_DATA(&dummyPixmap->pixmap) = pbits;
  243.     qdPushPixels(pGC, &dummyPixmap->pixmap, pDrawable,
  244.              gWidth, gHeight,
  245.              x + pci->metrics.leftSideBearing,
  246.              y - pci->metrics.ascent);
  247.     /* hack to prevent CopyPixmapFromOffscreen */
  248.     QD_PIX_DATA(&dummyPixmap->pixmap) = (unsigned char *)1;
  249.     tlCancelPixmap(dummyPixmap);
  250.     x += pci->metrics.characterWidth;
  251.     }
  252.     DEALLOCATE_LOCAL(pbits);
  253. }
  254.